# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=glibmm
pkgbase=mingw-w64-${_realname}-2.68
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-2.68"
pkgver=2.84.0
pkgrel=1
pkgdesc="Glib-- (glibmm) is a C++ interface for glib (V2.68) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnome.pages.gitlab.gnome.org/glibmm/'
msys2_repository_url='https://gitlab.gnome.org/GNOME/glibmm'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsigc++-3.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.gnome.org/sources/glibmm/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('56ee5f51c8acfc0afdf46959316e4c8554cb50ed2b6bc5ce389d979cbb642509')

build() {
  local -a _static_flags=(
    -DGIO_STATIC_COMPILATION
    -DGLIB_STATIC_COMPILATION
    -DGMODULE_STATIC_COMPILATION
    -DGOBJECT_STATIC_COMPILATION
  )

  local -a _meson_options=(
    --prefix=${MINGW_PREFIX}
    --buildtype=plain
    --wrap-mode=nodownload
    --auto-features=enabled
    -Dmaintainer-mode=false
    -Dbuild-documentation=false
    -Dbuild-examples=true
  )

  CFLAGS+=" ${_static_flags[@]} -Wno-attributes" \
  CXXFLAGS+=" ${_static_flags[@]} -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    "${_meson_options[@]}" \
    --default-library=static \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-static"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-static"

  CFLAGS+=" -Wno-attributes" \
  CXXFLAGS+=" -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    "${_meson_options[@]}" \
    --default-library=shared \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-shared"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-shared"
}

check() {
  ${MINGW_PREFIX}/bin/meson.exe test -C "build-${MSYSTEM}-static" || warning "Tests failed"
  ${MINGW_PREFIX}/bin/meson.exe test -C "build-${MSYSTEM}-shared" || warning "Tests failed"
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-static" --destdir "${pkgdir}"
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-shared" --destdir "${pkgdir}"

  sed -s "s|$(cygpath -wm /usr/bin)|/usr/bin|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/glibmm-2.68/proc/gmmproc
  sed -s 's|#!.*|#! /usr/bin/perl|g' -i "${pkgdir}${MINGW_PREFIX}"/lib/glibmm-2.68/proc/gmmproc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-2.68/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.tools" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-2.68/COPYING.tools"
}
